package com.hxht.cmp.controller;

import com.hxht.cmp.common.enums.ResultCode;
import com.hxht.cmp.common.result.ResultResponse;
import com.hxht.cmp.pojo.SearchCriteria;
import com.hxht.cmp.service.CasePlanService;
import com.hxht.cmp.service.CaseReviewService;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by gaozikun on 2017/7/10 0010.
 */
@RestController
@RequestMapping("review")
public class ReViewController {

    @Resource
    private CaseReviewService caseReviewService;
    @Resource
    private CasePlanService casePlanService;

    /**
     * @param courtId
     * @param size
     * @param status  0表示单个发法院，1表示区域法院
     * @return
     */
    @RequestMapping("getReviewIndex")
    public ResultResponse getReviewIndex(String courtId, String size, String status) {

        List<Map<String, Object>> plans = caseReviewService.getReviewIndex(courtId, size, status);
        if (null == plans || plans.size() < 1) {
            return ResultResponse.success();
        }
        return ResultResponse.success(plans);
    }

    /**
     * 成员变量status 0表示单个法院，1 表示区域法院
     * 成员变量review 0表示排期，1表示回顾
     * 0-0 单个法院排期
     * 0-1 单个法院回顾
     * 1-0 区域法院排期
     * 1-1 区域法院回顾
     *
     * @param searchCriteria
     * @return
     */
    @RequestMapping("countReviewOrPlan")
    public ResultResponse countReviewByConditions(SearchCriteria searchCriteria) {
        if (ObjectUtils.isEmpty(searchCriteria.getCourtUid()) || ObjectUtils.isEmpty(searchCriteria.getPage()) || ObjectUtils.isEmpty(searchCriteria.getPageSize()) || ObjectUtils.isEmpty(searchCriteria.getStatus()) || ObjectUtils.isEmpty(searchCriteria.getReview())) {
            return ResultResponse.failed(ResultCode.PARAMETER_NULL);
        }
        Integer count = caseReviewService.countReviewByConditions(searchCriteria);
        return ResultResponse.success(count);

    }

    /**
     * 成员变量status 0表示单个法院，1 表示区域法院
     * 成员变量review 0表示排期，1表示回顾
     * 0-0 单个法院排期
     * 0-1 单个法院回顾
     * 1-0 区域法院排期
     * 1-1 区域法院回顾
     *
     * @param searchCriteria
     * @return
     */
    @RequestMapping("getReviewOrPlan")
    public ResultResponse getReviewByConditions(SearchCriteria searchCriteria) {
        if (ObjectUtils.isEmpty(searchCriteria.getCourtUid()) || ObjectUtils.isEmpty(searchCriteria.getPage()) || ObjectUtils.isEmpty(searchCriteria.getPageSize()) || ObjectUtils.isEmpty(searchCriteria.getStatus()) || ObjectUtils.isEmpty(searchCriteria.getReview())) {
            return ResultResponse.failed(ResultCode.PARAMETER_NULL);
        }
        Map<String, Object> data = caseReviewService.getReviewByConditions(searchCriteria);
        return ResultResponse.success(data);

    }

    @RequestMapping("selectOnTimeByConditions")
    public ResultResponse selectOnTimeByConditions(SearchCriteria searchCriteria, String onTimeType) {
        if (ObjectUtils.isEmpty(searchCriteria.getCourtUid()) || ObjectUtils.isEmpty(searchCriteria.getPage()) || ObjectUtils.isEmpty(searchCriteria.getPageSize()) || ObjectUtils.isEmpty(searchCriteria.getStatus())) {
            return ResultResponse.failed(ResultCode.PARAMETER_NULL);
        }
        Map<String, Object> data = casePlanService.selectOnTimeByConditions(searchCriteria, onTimeType);
        return ResultResponse.success(data);
    }
}
